//
//  HMStatusViewModel.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/2/1.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMStatusViewModel: NSObject {
    var status:HMStatus?{
        didSet{
            
        }
    }
    
    var vipImage: UIImage?{
        
        guard let mbk = status?.user?.mbrank else{
            return nil
        }
        
        if mbk > 0 && mbk < 7 {
            return UIImage(named: "common_icon_membership_level\(mbk)")
        }
        
        return nil
    }
    
    var verifiedImg: UIImage?{
        guard let vfImg = status?.user?.verified else{
            return nil
        }
        
        switch vfImg {
        case 1:
            return UIImage(named: "avatar_vip")
        case 2,3,5:
            return UIImage(named: "avatar_enterprise_vip")
        case 220:
            return UIImage(named: "avatar_grassroot")
        default:
            return nil
        }
    }
    
    init(status: HMStatus) {
        super.init()
        self.status = status
        
        retweetCountStr = getCountString(self.status?.reposts_count ?? 0, defaultTitle: "转发")
        commentCountStr = getCountString(self.status?.comments_count ?? 0, defaultTitle: "评论")
        unlikeCountStr = getCountString(self.status?.attitudes_count ?? 0, defaultTitle: "赞")
    }
    
    var retweetCountStr: String?
    var commentCountStr: String?
    var unlikeCountStr: String?
    
    private func getCountString(count: Int,defaultTitle: String) -> String{
        if count > 0{
            
            if count < 10000{
                return "\(count)"
            }else {
                let result = CGFloat(count / 1000) / 10
                let resultStr = "\(result)万"
                if resultStr.containsString(".0"){
                    return resultStr.stringByReplacingOccurrencesOfString(".0", withString: "")
                }
                
                return resultStr
            }
        }
        
        return defaultTitle
    }
}
